package com.ssy.lingxi.logistics.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.logistics.model.enums.LogisticsOrderStatusEnum;
import com.ssy.lingxi.logistics.model.request.LogisticsHandleOrderListRequest;
import com.ssy.lingxi.logistics.model.request.LogisticsOrderConfirmRequest;
import com.ssy.lingxi.logistics.model.request.OrderIdOrCodeRequest;
import com.ssy.lingxi.logistics.model.response.LogisticsOrderHandleListResponse;
import com.ssy.lingxi.logistics.model.response.LogisticsOrderResponse;
import com.ssy.lingxi.logistics.service.ILogisticsOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @menu 物流能力 - 物流单处理 - 待确认物流单
 * @author yzc
 * @version 2.0.0
 * @date 2020/7/10
 */
@RestController
@RequestMapping("/logistics/orderWaitConfirm")
public class LogisticsOrderWaitConfirmController extends BaseController {

    @Resource
    private ILogisticsOrderService logisticsOrderService;

    /**
     * 物流单分页列表(待确认)
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/page")
    public Wrapper<PageData<LogisticsOrderHandleListResponse>> pageLogisticsOrder(LogisticsHandleOrderListRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        request.setStatus(LogisticsOrderStatusEnum.WAIT_CONFIRMED.getCode());
        return logisticsOrderService.pageHandleLogisticsOrder(request, sysUser);
    }

    /**
     * 物流单查询
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping(value = "/get")
    public Wrapper<LogisticsOrderResponse> getLogisticsOrder(OrderIdOrCodeRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();

        //参数校验
        if (Objects.isNull(request.getId()) && Objects.isNull(request.getCode())) {
            return Wrapper.fail("id或编号不能为空");
        }
        return logisticsOrderService.getHandleLogisticsOrder(request, sysUser);
    }

    /**
     * 物流单确认
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/confirm")
    public Wrapper<Void> updateOrderStatusConfirm(@RequestBody @Validated LogisticsOrderConfirmRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return logisticsOrderService.updateOrderStatusConfirm(request, sysUser);
    }
}
